package org.example.route.event.listener;

import org.example.route.event.OrderCancelEvent;
import org.example.route.event.OrderPayEvent;
import org.example.route.event.source.OrderCancelSource;
import org.example.route.event.source.OrderPaySource;
import org.example.route.mapper.PriceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class PriceListener {
 @Autowired
 private PriceMapper priceMapper;


 //订单减少处理
 @Async
 @EventListener
 public void handleEvent(OrderCancelEvent orderCancelEvent)
 {
    OrderCancelSource orderCancelSource = orderCancelEvent.getOrderCancelSource();
    priceMapper.beReleased(orderCancelSource.getPriceId());


 }

 @Async
 @EventListener
    public void handleEvent(OrderPayEvent orderPayEvent)
 {

     OrderPaySource orderPaySource = orderPayEvent.getOrderPaySource();
     priceMapper.bePayed(orderPaySource.getPriceId());
 }


}
